<?php
/*
	页面类型
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
model('core/core')->checklogin();
if($_RQ['op']=='main'){
	if(!$_RQ['id']){
		exi('参数错误','error');
	}
	$code=pdo_get('jy_exchange_code',array('id'=>$_RQ['id']));
	$info=pdo_get('jy_exchange_group',array('id'=>$code['groupid']));
	$goods=json_decode($info['goods'],true);
	foreach($goods as &$v){
		$g=pdo_get('jy_weishop_goods',array('id'=>$v['goodsid']),array('title','image','price'));
		$v['title']=$g['title'];
		$v['marketprice']=$g['price'];
		$v['image']=$g['image'];
		if($info['postagetype']!=1){
			$v['postage']=$info['postage'];
		}	
		$v['id']=$info['id'];
		$v['cid']=$code['id'];
	}
	set_html('title','兑换中心');
	$return['key']=$code['key'];
	$return['goods']=$goods;
	exi($return);
}

if($_RQ['op']=='post'){
	$post=get_postdata();
	pdo_update('jy_exchange_code',array('mid'=>$_SESSION['uid']),array('id'=>$post['cid'],'uniacid'=>$_SESSION['uniacid']));
	exi('','success','jy_exchange/order.create/main/num=1&goodsid='.$post['goodsid']);	
}